#!/bin/bash
#
# name: list_client_account.sh
# auth: doctype <https://t.me/ndiey>
# desc:
##
clear

if [ "${EUID}" -ne 0 ]; then
    echo "You need to run this script as root" && exit 1
fi

echo "======================== [ SSHD CLIENT LISTS ]"
echo "Username      | Expire date"
echo "----------------------------------------------"
while read file; do
    getClients="$(echo $file | cut -d ":" -f 1)"
    expireDate="$(chage -l $getClients | grep "Account expires" | awk -F": " '{print $2}')"
    getUid="$(echo $file | grep -v nobody | cut -d ":" -f 3)"
    if [[ $getUid -ge 1000 ]]; then
        printf "%-15s %2s\n" "$getClients" "$expireDate"
    fi
done < /etc/passwd
totalClient="$(awk -F ":" '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd | wc -l)"

echo "----------------------------------------------"
echo "totalClient: $totalClient pengguna"
echo "----------------------------------------------"
echo "Copyright 2021 Cybertize, Allright Reserved."
echo "=============================================="
echo
echo
echo "==================== [ OPENVPN CLIENT LISTS ]"
echo "Username      | Expire date"
echo "---------------------------------------------"
while read file; do
    UIDN=1000
    getClients="$(echo $file | cut -d ":" -f 1)"
    getUid="$(echo $file | grep -v nobody | cut -d ":" -f 3)"
    expireDate="$(chage -l $getClients | grep "Account expires" | awk -F": " '{print $2}')"
    if [[ $getUid -ge 1000 ]]; then
        printf "%-15s %2s\n" "$getClients" "$expireDate"
    fi
done < /etc/passwd
totalClient="$(awk -F ":" '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd | wc -l)"

echo "---------------------------------------------"
echo "Jumlah: $totalClient pengguna"
echo "---------------------------------------------"
echo "Copyright 2021 Cybertize, Allright Reserved."
echo "============================================="
